package com.scy.controller;


import com.scy.pojo.HostInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;

@RestController
@RequestMapping("/host")
public class HostController {

    @RequestMapping(value = "/getHostInfo")
    public HostInfo getHostInfo() {

        System.out.println("HostController类中的getHostInfo方法执行了");
        String hostAddress = "hostAddress";
        try {
            InetAddress localHost = InetAddress.getLocalHost();
            hostAddress = localHost.getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        HostInfo hostInfo = new HostInfo();

        if (hostAddress.equals("hostAddress")) {
            hostAddress="获取host的ip失败";
        }

        hostInfo.setHostName(hostAddress);
        return hostInfo;
    }
}
